﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DonutLandLibrary
{
    public class RandomGenerator
    {
        private static RandomGenerator currentInstance;
        private static Random random;
        private static readonly object syncLock = new object();

        protected RandomGenerator()
        {
            random = new Random();
        }

        public static RandomGenerator getInstance()
        {
            if (currentInstance == null)
            {
                currentInstance = new RandomGenerator();
            }

            return currentInstance;
        }

        public int RandomInt(int min, int max)
        {
          //  lock (syncLock)
           // { // synchronize
                return random.Next(min, max + 1);
            //}
        }

        public bool RandomBool()
        {
            int randomNumber;
            bool randomBool;

            randomNumber = RandomInt(0, 1);

            if (randomNumber == 0)
            {
                randomBool = false;
            }
            else
            {
                randomBool = true;
            }

            return randomBool;
        }

        public DonutLandLibrary.Robots.Robot.Direction RandomDirection()
        {
            int directionInt = RandomInt(0, 7);
            DonutLandLibrary.Robots.Robot.Direction direction;

            switch (directionInt)
            {
                case 0:
                    direction = Robots.Robot.Direction.N;

                    break;
                case 1:
                    direction = Robots.Robot.Direction.NE;

                    break;
                case 2:
                    direction = Robots.Robot.Direction.E;

                    break;
                case 3:
                    direction = Robots.Robot.Direction.SE;

                    break;
                case 4:
                    direction = Robots.Robot.Direction.S;

                    break;
                case 5:
                    direction = Robots.Robot.Direction.SW;

                    break;
                case 6:
                    direction = Robots.Robot.Direction.W;

                    break;
                case 7:
                    direction = Robots.Robot.Direction.NW;

                    break;
                default:
                    direction = RandomDirection();

                    break;
            }

            return direction;
        }
    }
}
